package com.framework.modules.finance;


import com.framework.entity.flow.FlowActiv;
import com.framework.exception.util.RespResult;
import com.framework.modules.sys.controller.AbstractController;
import com.framework.page.PageUtils;
import com.framework.service.FlowActivService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;

/**
 * 激活返现controller
 * @author wq
 */
@RestController
@RequestMapping("/sys/flowActiv")
public class FlowActivController extends AbstractController {
    @Autowired
    private FlowActivService flowActivService;

    /**
     * 激活返现列表
     * @param params
     * @return
     */
    @RequestMapping("/list")
    @RequiresPermissions("sys:flowactiv:list")
    public RespResult list(@RequestParam Map<String,Object> params){
        params.put("deptId",getUser().getDeptId());
        PageUtils page = flowActivService.queryActivAgentList(params);
        return RespResult.ok().put("page",page);
    }

    /**
     * 新增一条记录
     * @param flowActiv
     * @return
     */
    @RequestMapping("/insert")
    @RequiresPermissions("sys:flowactiv:insert")
    public RespResult insert(@RequestBody Map<String,Object> flowActiv){
        Long deptId=getUser().getDeptId();
        flowActivService.insertFlowActiv(flowActiv,deptId);
        return RespResult.ok();
    }

    /**
     * 修改
     * @param flowActiv
     * @return
     */
    @RequestMapping("/update")
    @RequiresPermissions("sys:flowactiv:update")
    public RespResult update(@RequestBody FlowActiv flowActiv){
        flowActivService.updateById(flowActiv);
        return  RespResult.ok();
    }

    /**
     * 删除
     * @param activId
     * @return
     */
    @RequestMapping("/delete")
    @RequiresPermissions("sys:flowactiv:delete")
    public RespResult delete(@RequestParam String activId){
        flowActivService.deleteFlowActivById(activId);
        return  RespResult.ok();
    }

    /**
     * 通过id查询
     * @param activId
     * @return
     */
    @RequestMapping("/queryById")
    @RequiresPermissions("sys:flowactiv:list")
    public RespResult queryById(@RequestParam String activId){
        Map<String,Object> flowActiv=flowActivService.queryActivAgentById(activId);
        return RespResult.ok().put("flowActiv",flowActiv);
    }
}
